/*jQuery Plugin*/
(function ($) {
    $.fn.animateFlash = function(option){
        // var default = {
        //     'xx':1,
        //     'yy':2
        // };
        // default  = $.extend(default, option);
        
            /*添加控制按钮*/
            var t;
            var that = this;
            var navBar = document.createElement('ul');
            navBar.setAttribute('class','nav');
            for(var i = 0,len = this.find('.pic li').length; i < len;i++){
                navBar.appendChild(document.createElement('li'));
            }
            var navBg = document.createElement('div');
            navBg.setAttribute('class','navbg');
            this.find('div:first').append(navBg);
            this.find('div:first').append(navBar);
            // console.log(this);
            /*控制动态切换*/
            var bgcolor = ['#4085d2', '#fdeeeb', '#1B4046', '#D7DEE4', '#0AA9E0', '#D8DDE3', '#0C1222']
            var index = 0;
            function autoAnimate(){
                $piclis = that.find('.pic li');
                if(index >= $piclis.length) index = 0;
                $piclis.hide();
                $piclis.eq(index).show(200);
                that.css('background',bgcolor[index]);
                // console.log(that);
                that.find('.nav li').removeClass('navnow');
                that.find('.nav li').eq(index).addClass('navnow');
                index++;
            }
            autoAnimate();
            t = setInterval(autoAnimate,2000);
            $piclis.hover(
                function(){
                    clearInterval(t);
            },function(){
                t = setInterval(autoAnimate,2000);
            });
            this.find('.nav li').each(function(k){
                $(this).click([k],function(e){
                    that.find('.nav li').removeClass('navnow');
                    that.addClass('navnow');
                    index = e.data[0];
                    autoAnimate();
                    clearInterval(t);
                    t = setInterval(autoAnimate,2000);
                    // console.log(e.data[0]);
                });
            });
    };


} (jQuery) );


